var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/print/PrintModal.tsx
var PrintModal_exports = {};
__export(PrintModal_exports, {
  openPrintModal: () => openPrintModal
});
module.exports = __toCommonJS(PrintModal_exports);
var import_react = require("react");
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_service = require("./service");
var import_static = require("./static");
var import_util2 = require("./util");
var global = {
  printParams: null,
  close: import_util.emptyFn,
  modalIns: null
};
function fuzzyMatchObject(filterDataObj, searchStr, keysToMatch) {
  const pattern = new RegExp(searchStr, "i");
  for (const key of keysToMatch) {
    const value = filterDataObj[key];
    if (value && pattern.test(value)) {
      return true;
    }
  }
  return false;
}
function PrintContent() {
  const { printParams } = global;
  const tableRef = (0, import_util.useApi)();
  const modalCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const onSearchHandler = (0, import_util.useRefCallback)((value) => {
    tableRef.current.getApi().filter((item) => fuzzyMatchObject(item, value, ["name"]));
  });
  const validDataAndStartFlow = (0, import_util.useRefCallback)(async () => {
    var _a;
    const {
      printParams: { batchPrintList, source_sys }
    } = global;
    const selectData = tableRef.current.getApi().getSelectedData()[0];
    if (!selectData) {
      await (0, import_util2.wfAlert)(import_util2.info.alertTitle, import_util2.info.selectTemplate);
      return;
    }
    switch (selectData.controlType) {
      case import_static.ControlType.FanRuan: {
        const printList = batchPrintList.map((item) => ({
          url: import_util.iup.getAbsoluteUrl(`${item.url}`),
          bizId: item.bizId
        }));
        const res = await (0, import_service.getPrintServer)();
        const params = {
          viewlet: selectData.fileName,
          token: ((_a = import_util.iup.getUser()) == null ? void 0 : _a.accessToken) ?? null,
          bizCode: selectData.bizCode,
          source_sys,
          bizDataParam: JSON.stringify(printList)
        };
        if (res.code === 0) {
          import_util.iup.open(
            `http://${res.data}/webroot/decision/view/report`,
            selectData.previewType !== import_static.PREVIEW_TYPE.PAGING ? { ...params, op: selectData.previewType } : params
          );
        } else {
          await (0, import_util2.wfAlert)(import_util2.info.printError, res.message);
        }
        break;
      }
      case import_static.ControlType.Platform: {
        import_util.iup.open("/print", {
          microAppName: "printDesign",
          appTitle: "打印预览",
          id: JSON.stringify(batchPrintList),
          templateId: selectData.id,
          bizCode: selectData.bizCode
        });
        break;
      }
      default: {
        await (0, import_util2.wfAlert)(import_util2.info.printError, "暂不支持该类型的打印");
      }
    }
  });
  (0, import_react.useEffect)(() => {
    global.modalIns = modalCtx.ins;
    modalCtx.ins.setApi({
      invokeOkHandler: validDataAndStartFlow,
      invokeCancelHandler: async () => {
        var _a, _b, _c;
        await ((_b = (_a = global.printParams).cancelback) == null ? void 0 : _b.call(_a));
        (_c = global.close) == null ? void 0 : _c.call(global);
      }
    });
    tableRef.current.getApi().setSelected(0);
  }, []);
  const compProps = (0, import_react.useMemo)(() => {
    var _a;
    const columnProps = {
      sortable: false,
      resizable: false,
      columnSort: false
    };
    return {
      labelStyle: {
        width: 65,
        marginLeft: "6px",
        display: "flex",
        flexDirection: "column",
        justifyContent: "center"
      },
      tableProps: {
        headerHeight: 32,
        rowHeight: 30,
        style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
        columns: [
          {
            ...columnProps,
            header: import_util2.info.templateCode,
            dataIndex: "templateCode"
          },
          {
            ...columnProps,
            header: import_util2.info.name,
            tooltip: true,
            dataIndex: "name"
          },
          {
            ...columnProps,
            header: import_util2.info.remark,
            tooltip: true,
            dataIndex: "remark"
          },
          {
            ...columnProps,
            header: import_util2.info.sharePolicy,
            tooltip: ({ row }) => {
              const sharePolicy = row.sharePolicy;
              return sharePolicy === import_util2.SharePolicyEnum.GROUP ? import_util2.info.group : sharePolicy === import_util2.SharePolicyEnum.CU ? import_util2.info.cu : sharePolicy === import_util2.SharePolicyEnum.ORG ? import_util2.info.org : "";
            },
            dataIndex: "sharePolicy",
            width: 90,
            render: ({ row }) => {
              const sharePolicy = row.sharePolicy;
              return sharePolicy === import_util2.SharePolicyEnum.GROUP ? import_util2.info.group : sharePolicy === import_util2.SharePolicyEnum.CU ? import_util2.info.cu : sharePolicy === import_util2.SharePolicyEnum.ORG ? import_util2.info.org : "";
            }
          },
          {
            ...columnProps,
            header: import_util2.info.shareTenant,
            tooltip: ({ row }) => {
              const sharePolicy = row.sharePolicy;
              return sharePolicy === import_util2.SharePolicyEnum.CU ? row.shareTenantName : sharePolicy === import_util2.SharePolicyEnum.ORG ? row.shareOrgName : "";
            },
            render: ({ row }) => {
              const sharePolicy = row.sharePolicy;
              return sharePolicy === import_util2.SharePolicyEnum.CU ? row.shareTenantName : sharePolicy === import_util2.SharePolicyEnum.ORG ? row.shareOrgName : "";
            }
          },
          {
            ...columnProps,
            header: import_util2.info.previewType,
            width: 130,
            flex: 1,
            dataIndex: "previewType",
            editor: {
              xtype: "select",
              nameField: "previewName",
              request: async (row) => {
                return row.controlType === import_static.ControlType.FanRuan ? import_static.FANRUANOPTIONS : import_static.PLATFORMOPTIONS;
              }
            }
          }
        ],
        dataSource: ((_a = printParams.data) == null ? void 0 : _a.map((item) => {
          var _a2, _b;
          return {
            ...item,
            previewType: item.controlType === import_static.ControlType.FanRuan ? import_static.PREVIEW_TYPE.PAGING : import_static.PREVIEW_TYPE.DEFAULT,
            previewName: item.controlType === import_static.ControlType.FanRuan ? (_a2 = import_static.FANRUANOPTIONS.find((option) => option.value === import_static.PREVIEW_TYPE.PAGING)) == null ? void 0 : _a2.label : (_b = import_static.PLATFORMOPTIONS.find((option) => option.value === import_static.PREVIEW_TYPE.DEFAULT)) == null ? void 0 : _b.label
          };
        })) || []
      }
    };
  }, []);
  return /* @__PURE__ */ React.createElement(import_util.Layout, { style: { height: 400, padding: "5px 12px" } }, /* @__PURE__ */ React.createElement(import_util.Layout, { direction: "row", style: { width: "90%", margin: "12px 0" } }, /* @__PURE__ */ React.createElement(import_baseComponent.Search, { placeholder: import_util2.info.searchEmptyText, allowClear: true, onSearch: onSearchHandler })), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_functionalComponent.Table, { ref: tableRef, showRowNumber: true, ...compProps.tableProps })));
}
async function openPrintModal({ ...props }) {
  global.printParams = props;
  global.printParams.startFlowParam = {};
  global.close = () => {
    var _a;
    global.close = import_util.emptyFn;
    (_a = global.modalIns) == null ? void 0 : _a.destroy();
    global.modalIns = null;
  };
  await (0, import_util2.wfModal)({
    title: import_util2.info.createPrintTitile,
    content: /* @__PURE__ */ React.createElement(PrintContent, null),
    width: 750
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  openPrintModal
});
